<template>
  <div class="album-container">
    <h4
      v-if="title"
      class="title">
      {{ title }}
    </h4>
    <div class="content">
      <div
        v-for="item in albums"
        :key="item.id"
        @click="toAlbumDetail(item.id, item.artistId as string)"
        class="album">
        <el-image
          lazy
          :src="item.cover" />
        <span class="iconfont play">&#xea83;</span>
        <span class="album-name">{{ item.name }}</span>
        <span>{{ item.publishTime }}</span>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { inject } from 'vue';
import { Album } from '../model';
import { getTheme } from '../utils/util';
import { useRouter } from 'vue-router';
//主题配置
const color = getTheme().get('fontColor');
const colorBlack = getTheme().get('fontBlack');
const boxShadow = getTheme().get('shadow');

const router = useRouter();

//设置隐藏滚动条
const hideScroll = inject('hideScroll') as Function;

//跳转专辑详情
const toAlbumDetail = (id: string, artistId: string) => {
  hideScroll();
  router.push({
    name: 'album',
    query: {
      id,
      artistId,
    },
  });
};

//声明组件接受值
defineProps<{
  //专辑数组
  albums: Album[];
  //标题
  title?: string;
}>();
</script>

<style lang="less" scoped>
@font-color: v-bind(color);
@font-color-light-black: v-bind(colorBlack);
@shadow: v-bind(boxShadow);
@font-color-gray: #7b7b7b;
@font-color-green: #1ed2a9;

.album-container {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;

  .title {
    font-weight: 520;
    font-size: 20px;
    letter-spacing: 1px;
    width: 80vw;
    color: @font-color;
    padding-left: 7.2px;
  }

  .content {
    width: 80vw;
    display: flex;
    flex-wrap: wrap;

    .album {
      display: flex;
      flex-direction: column;
      margin: 20px 7.2px 0;
      position: relative;

      &:hover .el-image {
        transform: translateY(-5px);
      }

      &:hover:after {
        opacity: 1;
        transform: translateY(-5px);
      }
      &:hover .play {
        opacity: 1;
      }
      .el-image {
        width: 190px;
        height: 190px;
        object-fit: cover;
        box-shadow: @shadow;
        border-radius: 10px;
        transition: 0.4s;
      }
      &::after {
        content: '';
        top: 0;
        height: 190px;
        width: 190px;
        border-radius: 10px;
        z-index: 9;
        background-color: rgba(0, 0, 0, 0.6);
        transition: 0.4s;
        position: absolute;
        opacity: 0;
      }
      .play {
        z-index: 10;
        display: inline-block;
        margin: 0;
        color: rgb(245, 245, 245);
        font-size: 50px;
        position: absolute;
        top: 57.5px;
        left: 70px;
        opacity: 0;
        &:hover {
          color: @font-color-green;
        }
        cursor: pointer;
      }
      .album-name {
        font-size: 13px;
        color: @font-color;
        margin-top: 10px;
      }
      span {
        margin-top: 5px;
        display: inline-block;
        font-size: 12px;
        width: 190px;
        color: @font-color-gray;
      }
    }
  }
}
</style>
